<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/ajax.js"></script>
</head>
<body>
    <button>点击发送ajax</button>
    <script>
        // localStorage.clear();
        let btnEle = document.querySelector("button");
        btnEle.onclick = function (){
            
            // console.log(sessionStorage);

            // console.log(localStorage);
            if( localStorage.length == 0 ){
                ajax({
                    url:'../php/ajax.php',
                    data:{
                        name:'zhangsan',
                        age:20,
                    },
                    dataType:'json',
                    contentType:true,
                    method:'post',
                    success(res){
                        localStorage.setItem('data',JSON.stringify(res.data));
                        // sessionStorage.setItem('data',JSON.stringify(res.data));
                        
                    }
                });
            } else {
                console.log(JSON.parse(localStorage.getItem('data')));
            }
        }
    </script>
</body>
</html>